package cn.sirun.com.fca.personal.center.presenter.impl;


import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.util.rx.SimpleObserver;

import cn.sirun.com.fca.personal.center.constant.MessageActionConst;
import cn.sirun.com.fca.personal.center.loader.MessageLoader;
import cn.sirun.com.fca.personal.center.model.request.MessageRequest;
import cn.sirun.com.fca.personal.center.model.response.MessageResponse;
import cn.sirun.com.fca.personal.center.presenter.IMessagePresenter;
import cn.sirun.com.fca.personal.center.presenter.MessageFlowPresenter;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.subjects.BehaviorSubject;

public class MessagePresenter extends MessageFlowPresenter<MessageLoader> implements IMessagePresenter {
    private BehaviorSubject<BaseResponse> mBehaviorSubject = BehaviorSubject.create();

    @Override
    protected MessageLoader createLoader() {
        return new MessageLoader();
    }





    @Override
    public void getMessageList(final MessageRequest request) {
        getLoader().getMessageList(request)
                .takeUntil(mBehaviorSubject)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SimpleObserver<BaseResponse<MessageResponse>>() {

                    @Override
                    public void onNext(BaseResponse<MessageResponse> submitPhoneResponse) {
                        super.onNext(submitPhoneResponse);
                        MessagePresenter.this.getActionListener().onAction
                                (MessageActionConst.Normal.ACTION_REQUEST_MESSAGE,
                                        submitPhoneResponse);
                    }
                });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mBehaviorSubject.onComplete();
    }



}
